package com.cqq.auth.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cqq.auth.dao.OperateLogDao;
import com.cqq.auth.dao.domain.OperateLog;
import com.cqq.auth.service.OperateLogService;
import com.cqq.auth.service.bean.OperateLogBean;
import com.cqq.auth.service.exception.OperateLogServiceException;
import com.cqq.common.core.base.BaseService;
import com.cqq.common.core.constant.CommonMessage;
import com.cqq.common.core.util.BeanUtil;

@Service("operateLogService")
public class OperateLogServiceImpl extends BaseService implements OperateLogService {

	private static final Logger logger = LoggerFactory.getLogger(OperateLogServiceImpl.class);
	
	@Autowired
	private OperateLogDao operateLogDao;
	
	
	public void addOperateLog(OperateLogBean log)
			throws OperateLogServiceException {
		logger.debug("addOperateLog ...");
		if(log==null || StringUtils.isBlank(log.getSystemCode())
				|| log.getType()==null
				|| log.getStatus()==null
				|| log.getUserId()==null
				|| StringUtils.isBlank(log.getUsername())
				|| log.getOperateTime()==null){
			throw super.buildException(new OperateLogServiceException(CommonMessage.COMMON_PARAM_EMPTY));
		}
		OperateLog l=BeanUtil.copy(log, OperateLog.class);
		this.operateLogDao.add(l);
		log.setId(l.getId());
		logger.debug("addOperateLog ok! {}",log);
	}

}
